/**
*@Author: QWP
*@Description: 表头的共享存储数据
*@Date 2023-08-14 14:58
*/
import { defineStore } from 'pinia'
import router from '@/router'
import { useLoginStore } from './../module/login'

interface LoginState {
  storeCols: object, 
}

const setKey = (): string => {
  const userId = useLoginStore().userInfo['userId'] || '';
  const path = router.currentRoute.value.path || '';
  return `${path}_${userId}`
}

export const useTableColStore = defineStore('tableColStore', {
  state: (): LoginState => {
    return {
      storeCols: {}, 
    }
  },
  getters: {
    getCols: (state): any[] => {
      return state.storeCols[setKey()] || []
    },
  },
  actions: {
    setStoreCols(data: any[]) {
      this.storeCols[setKey()] = data
    },
  },
  persist: true,
})